<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function sumMaker(length) {
            const nums = []
            function sum(...args) {
                nums.push(...args)
                if (nums.length >= length) {
                    return nums.slice(0, length).reduce((a, b) => a + b, 0)
                    nums = []
                }
                else {
                    return sum
                }
            }
            return sum
        }
        const sum = sumMaker(6)
        console.log(sum(1)(2)(3)(4)(5)(6))
    </script>
</body>

</html>